package java0709Exception;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class Test03 {

	public static void main(String[] args) {

		
		try {
			
			CompareStr();
		}catch (NullPointerException e) {
			System.out.println("空指针异常：");
			e.printStackTrace();
		}finally {
			System.out.println("程序运行结束");
		}
		/*
		 * getmessage有信息
		 */
//		try {
//			test03();
//		} catch (Exception e) {
//			System.out.println("发生异常：" + e.getMessage());
//			 e.printStackTrace();
//		}

	}
	/*
	 * 对于getmessage()方法，不同的异常会抛出的信息不一样，这个不为空
	 */
	private static void test03() throws FileNotFoundException {
		// 文件输入流，会引发文件无法找到异常
		FileInputStream fis = new FileInputStream("D:\\temp\\jvm\\Hello2.java");
	}
	
	
	

	private static void CompareStr() throws NullPointerException {
		// 定义字符串
					String str1 = null ;
					String str2 = "XXXX";
		
		if (str1!= null && str2 != null) {
			if (str1.compareTo(str2) > 0) {
				System.out.println("str1大于str2");
			} else if (str1.compareTo(str2) < 0) {
				System.out.println("str1小于str2");
			} else {
				System.out.println("str1等于str2");
			}
			
		} else {
			throw new NullPointerException();
		}
	}

}
